home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / SAT / SAT Lib ƒ / SAT.p < prev   
Encoding:
Text File  |  1993-09-21  |  7.1 KB  |  172 lines  |  [TEXT/PJMM]

  1. unit SAT;
  2.  
  3. interface
  4.  
  5.     type
  6.         {BMPtr = ^BitMap;}
  7.  
  8.         FacePtr = ^Face;
  9.         Face = record
  10.                 colorData: Ptr;
  11.                 resNum: integer;
  12.                 iconMask: BitMap;
  13.                 rowBytes: integer;
  14.                 next: FacePtr;
  15.                 maskRgn: RgnHandle;
  16.             end;
  17.  
  18.         SpritePtr = ^Sprite;
  19.         Sprite = record
  20. { Variables that you should change as appropriate }
  21.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  22.                 position: Point;
  23.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  24.                                         {hotRect is set by you. hotrect2 is set by SAT - forget about it}
  25.                 face: FacePtr; { Pointer to the Face (appearance) to be used. }
  26.                 task: ProcPtr; { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  27.                 hittask: ProcPtr; { Callback in collisions. }
  28. { SAT variables that you shouldn't change: }
  29.                 oldpos: point; { The 'task' routine is not allowed to change this! }
  30.                 next, prev: SpritePtr;
  31.                 r, oldr: Rect;
  32. { Variables for internal use by the sprites. Use as you please. }
  33.                 layer: integer; {For free use, or for sorting.}
  34.                 speed: Point; { Can be used for speed, but not necessarily. }
  35.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  36.                 appPtr: Ptr; {Pointer for use by the application - i.e. pointer to extra data}
  37.                 appLong: Longint; {Longint for free use by the application.}
  38.             end;
  39.  
  40. {Type for SATs pattern utilities.}
  41.     type
  42.         SATPattern = record
  43.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  44.                 thePat: PixPatHandle; {or PatHandle}
  45.             end; {record}
  46.         SATPatPtr = ^SATPattern;
  47.         SATPatHandle = ^SATPatPtr;
  48.  
  49.  
  50. {Temp}
  51.         UpdatePtr = ^UpdateRec;
  52.         UpdateRec = record
  53.                 updateRect: Rect;
  54.                 next: UpdatePtr;
  55.             end;
  56.  
  57. {Configuration types: VPositionSort and KindCollision are defaults.}
  58. {SortType = (VPositionSort, LayerSort, NoSort);}
  59. {CollisionType = (KindCollision, ForwardCollision, BackwardCollision, NoCollision);}
  60.  
  61.     const
  62. {Sorting options}
  63.         VPositionSort = 0;
  64.         LayerSort = 1;
  65.         NoSort = 2;
  66. {Collision detection options}
  67.         KindCollision = 0;
  68.         ForwardCollision = 1;
  69.         BackwardCollision = 2;
  70.         NoCollision = 3;
  71.  
  72.     var
  73. {$J+}
  74.         SATwind: WindowPtr; { The window that SAT draws in. }
  75.  
  76.         offScreen: GrafPtr;        { Offscreen image }
  77.         backScreen: GrafPtr;    { Background image }
  78.         offScreenGD, BackScreenGD: GDHandle; {Graphic devices for offScreen and BackScreen}
  79.  
  80.         ox, oy: Longint; { Origin-variables for PlotFast }
  81.         SATpict, SATbwpict: integer;
  82.         sRoot: SpritePtr; {Root of the sprite list}
  83.  
  84.         offSizeH, offSizeV: integer; {Size of the animation area}
  85.  
  86. { Screen size parameters. }
  87. { Usually, you will only need to inspect offSizeH and offSizeV, and sometimes ourDepth and colorFlag }
  88. {The others are subject to change or go away}
  89.         ourDevice: GDHandle;
  90.         ourScreen: PixMapHandle;
  91.         ourBaseAddr: Ptr;
  92.         ourRowBytes: Integer;
  93.         ourBounds: Rect;
  94.         ourDepth: Integer; { Depth of screen and offscreens }
  95.         colorFlag: Boolean; { Is this Mac color capable? }
  96.         anyMonsters: Boolean; { False when no sprites with kind < -1 are active }
  97.  
  98.         updateRoot: UpdatePtr; {temp}
  99. {$J-}
  100.  
  101. {Initializing and customizing}
  102.     procedure ConfigureSAT (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  103.     function InitSAT (pictID, bwpictID, Xsize, Ysize: integer): WindowPtr;
  104.     function CustomInitSAT (pictID, bwpictID: integer; SATdrawingArea: Rect; preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, centerDrawingArea, fillScreen, dither4bit: Boolean): WindowPtr;
  105. {Maintainance, background manipulation etc.}
  106.     function SATDepthChangeTest: Boolean;
  107.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  108.     procedure PeekOffscreen;
  109. {Drawing}
  110.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: GrafPtr; theGDevice: GDHandle; where: Point; fast: boolean);
  111.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; fast: boolean); {*NEW*}
  112.     procedure SATCopyBits (src, dest: GrafPtr; destGD: GDHandle; srcPt, destPt: Point; width, height: integer; fast: Boolean);
  113.     procedure SATCopyBitsToScreen (src: GrafPtr; srcPt, destPt: Point; width, height: integer; fast: Boolean); {*NEW*}
  114.     procedure SATBackChanged (r: Rect); {Tell SAT about changes in BackScreen}
  115.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  116.     procedure SATSetPortBackScreen; {Use before using QuickDraw on BackScreen}
  117.     procedure SATSetPortScreen; {Use to restore after drawing off/backscreen}
  118. {Sprite handling}
  119.     function GetFace (resNum: integer): FacePtr;
  120.     procedure DisposeFace (theFace: FacePtr);
  121.     function NewSprite (kind, hpos, vpos: integer; callback, setup, hittask: ProcPtr): SpritePtr;
  122.     function NewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; callback, setup, hittask: ProcPtr): SpritePtr;
  123.     procedure KillSprite (who: Spriteptr);
  124. {Animating}
  125.     procedure RunSAT (fast: Boolean); {The heart of the whole package!}
  126. {Menu bar}
  127.     procedure ShowMBar;
  128.     procedure HideMBar (wind: WindowPtr);
  129. {Special functions for advanced programmers}
  130.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  131.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  132.     procedure SATSetSpriteRecSize (theSize: longint);
  133.     procedure SkipSAT;
  134.     procedure KillSAT; {Dispose of offscreen buffers to allow re-init}
  135. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  136.     procedure SATMakeOffscreen (var portP: GrafPtr; rectP: Rect; var retGDevice: GDHandle); {Make offscreen buffer in current screen depth and CLUT.}
  137.     procedure SATDisposeOffScreen (portP: GrafPtr; theGDevice: GDHandle); {Get rid of offscreen}
  138.     function CreateOffScreen (bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  139.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  140.  
  141. {Utilities}
  142.     procedure DrawInt (i: integer);
  143.     procedure DrawLong (l: longint);
  144.     function Rand (n: integer): integer;
  145.     function Rand10: integer;
  146.     function Rand100: integer;
  147.     procedure ReportStr (str: str255);
  148.     function QuestionStr (str: str255): Boolean;
  149.     procedure CheckNoMem (p: Ptr); {Might replace this by SATnewPtr}
  150.     procedure SetMouse (where: point);
  151. {Pattern utilities}
  152.     procedure SATPenPat (SATpat: SATPatHandle);
  153.     procedure SATBackPat (SATpat: SATPatHandle);
  154.     function SATGetPat (patID: integer): SATPatHandle;
  155.     procedure SATDisposePat (SATpat: SATPatHandle);
  156. {Sound}
  157.     procedure SATSoundInit; {Called from InitSAT}
  158.     procedure SATSoundPlay (TheSound: Handle; Priority: integer; CanWait: boolean);
  159.     procedure SATSoundEvents; {Call this once in a while when not calling RunSAT often}
  160.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  161.     procedure SATSoundOn;
  162.     procedure SATSoundOff;
  163.     function SATSoundDone: Boolean; {Any sound going on ?}
  164.     function SATGetSound (sndId: integer): handle;        { To load a sound and get a handle for SATSoundPlay }
  165.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  166.     procedure SATDisposeSound (theSnd: handle);
  167. {Experimental, likely to be renamed/removed/changed:}
  168.     procedure SATSoundPlay2 (theSound: Handle; priority: integer; canWait, skipIfSame: Boolean);
  169.     procedure SATSoundPlayEasy (theSound: handle; canWait: boolean);
  170.  
  171. implementation
  172. end.